package pl.grabar.clinic.client.web.actions.reception.visit;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import pl.grabar.clinic.core.dao.Dao;
import pl.grabar.clinic.core.domain.person.Patient;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@ParentPackage(value = "json")
@Action("list/loadDictionary")
@InterceptorRef("grabarStack")
@Results({@Result(name = "success", type = "json")})
public class LoadPatientsJsonAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -6478629467284623579L;

	private static final Log LOG = LogFactory.getLog(LoadPatientsJsonAction.class);

	@Autowired
	private Dao<Patient> patientDao;

	private String regex;

	private Map<Long, String> listPatients = new HashMap<>();

	private String error = "";

	private Integer page;

	private Integer page_limit;

	@Override
	public void prepare() throws Exception {

	}

	@Action("findPatients")
	public String findPatients() throws Exception {
		for (Patient patient : patientDao.findAll(page, page_limit, "", "asc")) {
			listPatients.put(patient.getId(), patient.getFullName()+" - "+patient.getPesel());
		}
		return SUCCESS;
	}

	public String execute() {
		return SUCCESS;
	}
	/* AKCESORY */

	public String getRegex() {
		return regex;
	}

	public void setRegex(String regex) {
		this.regex = regex;
	}

	public Map<Long, String> getListPatients() {
		return listPatients;
	}

	public void setListPatients(Map<Long, String> listPatients) {
		this.listPatients = listPatients;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getPage_limit() {
		return page_limit;
	}

	public void setPage_limit(Integer page_limit) {
		this.page_limit = page_limit;
	}

	public void setPatientDao(Dao<Patient> patientDao) {
		this.patientDao = patientDao;
	}


}
